#!/bin/bash
# route_depth_analysis.sh

echo "=== 路由路径深度分析 ==="

# 修改目标地址
TARGETS=("43.135.186.249" "157.230.165.12")

for target in "${TARGETS[@]}"; do
    echo "🔍 分析 $target 的路由路径:"
    
    # 详细路由追踪
    traceroute -n -q 1 -w 1 $target | \
        awk '{
            if(NR>1 && $2!="*") {
                printf "跳数%2d: %-15s", NR-1, $2
                for(i=3;i<=NF;i++) if($i!="ms") printf " %s", $i
                printf "\n"
            }
        }' | head -10
    
    # 计算平均跳数延迟
    echo "路由统计:"
    traceroute -n -q 3 -w 1 $target 2>/dev/null | \
        grep -E "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" | \
        awk '{
            sum=0; count=0
            for(i=3;i<=NF;i++) if($i~/ms/) {
                gsub("ms","",$i); sum+=$i; count++
            }
            if(count>0) printf " 跳数%d: 平均延迟%.2fms\n", NR, sum/count
        }'
    echo ""
done